const path = require('path')
const { DefinePlugin } = require('webpack')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = {
  mode: 'development',
  devtool: false,
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.js$/g,
        exclude: /node_module/,
        use: ['babel-loader']
        // use: [{
        //   loader: 'babel-loader',
        //   options: {
        //     // 使用插件
        //     // plugins: [
        //     //   '@babel/plugin-transform-arrow-functions',
        //     //   '@babel/plugin-transform-block-scoping'
        //     // ]
        //     // 使用预设
        //     presets: [
        //       [
        //         '@babel/preset-env',
        //         // 设置支持的浏览器
        //         { targets: 'chrome 91' }
        //       ]
        //     ]
        //   }
        // }]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      title: 'webpack666',
      template: './public/index.html'
    }),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: 'public',
          globOptions: {
            ignore: ['**/index.html']
          }
        }
      ]
    }),
    new DefinePlugin({
      BASE_URL: '"./"'
    })
  ]
}